package com.acwing.partition11;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class AC1024装箱问题 {

    public static void main(String[] args) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split("\\s+");
        int capacity = Integer.parseInt(s[0]);
        int n = Integer.parseInt(reader.readLine().split("\\s+")[0]);
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(reader.readLine().split("\\s+")[0]);
        writer.write(String.valueOf(dynamicProgramming(capacity, nums)));
        writer.flush();
    }

    private static int dynamicProgramming(int capacity, int[] nums) {
        int[] dp = new int[capacity + 1];
        for (int i = 0; i < nums.length; i++) {
            for (int j = capacity; j >= nums[i]; j--) {
                dp[j] = Math.max(dp[j], dp[j - nums[i]] + nums[i]);
            }
        }
        return capacity - dp[capacity];
    }
}